package interview.i_001_algorithm;

import java.util.BitSet;
import java.util.concurrent.ThreadLocalRandom;

/**
 * (亿)大数组去重
 * https://mp.weixin.qq.com/s/rjGqxUvrEqJNlo09GrT1Dw
 */
public class T004_ArrayRemoveRepeat {
    static ThreadLocalRandom threadRandom = ThreadLocalRandom.current();
    static Integer[] array = new Integer[9999];

    static {
        for (int i = 0; i < array.length; i++) {
            array[i] = threadRandom.nextInt(Integer.MIN_VALUE, Integer.MAX_VALUE);
        }
    }

    public static void main(String[] args) {
        long count = 0L;
        BitSet positive = new BitSet(Integer.MAX_VALUE);
        BitSet negative = new BitSet(Integer.MAX_VALUE);
        for (int i : array) {
            if (i >= 0) {
                if (!positive.get(i)) {
                    positive.set(i);
                    count++;
                }
            } else {
                i = Math.abs(i);
                if (!negative.get(i)) {
                    negative.set(i);
                    count++;
                }
            }
        }
        System.out.println(count);
        System.out.println(positive.size() + negative.size());
        System.out.println(positive.length() + negative.length());

        array = null;
        System.gc();
        System.out.println(positive);
        System.out.println(negative);
    }
}
